<template>
    <div class="subpage card-list-container">
        <div v-if="bankCardList.length > 0">
            <ul class="card-list-top">
                <li v-for="(item, index) in bankCardList" :key="index">
                    <div class="bank-img">
                        <img src="../../../assets/img/bank_up_icon.png" alt="">
                    </div>
                    <div class="bank-info">
                        <p class="bank-name">{{item.bankName}}</p>
                        <p class="bank-type">储蓄卡</p>
                        <p class="bank-num">
                            <span>****</span>
                            <span>****</span>
                            <span>****</span>
                            <span>{{item.cardNumber}}</span>
                        </p>
                    </div>
                </li>
            </ul>
            <van-button round class="u-btn-default unbind-btn" @click="unBindCard" v-if="bankCardList.length > 0">解绑</van-button>
        </div>
        <p v-else class="no-data">暂未绑卡~</p>
    </div>
</template>

<script>
export default {
    data() {
        return {
            bankCardList: [],
            bankCardId: ''
        }
    },
    created() {
        this.getBankCard()
    },
    methods: {
        getBankCard() {
            this.$api.get('/api/user/getBankCard')
                .then((res) => {
                    this.bankCardList = res.data
                    this.bankCardId = res.data.length > 0 ? res.data[0].id : ''
                })
        },
        unBindCard() {
            this.$router.push({
                path: '/my/personalInfo/unbindBankCard/' + this.bankCardId
            })
        }
    }
}
</script>

<style lang="scss" scoped>
    .card-list-container {
        width: 100%;
        padding: 10px 20px 0;
        box-sizing: border-box;
        background-color: #fff;
        .card-list-top {
            width: 100%;
            li {
                display: flex;
                width: 100%;
                height: 110px;
                margin-bottom: 15px;
                padding: 12px;
                box-sizing: border-box;
                border-radius: 8px;
                background: url('https://ym-1251385011.cos.ap-guangzhou.myqcloud.com/images/20190929/15697234816178100.png') no-repeat center;
                background-size: cover;
                box-shadow: 0 4px 10px #ccc;
                color: #fff;
                overflow: hidden;
                .bank-img {
                    width: 30px;
                    height: 30px;
                    margin-right: 18px;
                    border-radius: 50%;
                    overflow: hidden;
                    img {
                        width: 30px;
                        height: 30px;
                        object-fit: cover;
                    }
                }
                .bank-info {
                    flex: 1;
                    .bank-name {
                        margin-top: 4px;
                        font-size: 16px;
                    }
                    .bank-type {
                        margin: 10px 0 20px;
                        font-size: 12px;
                    }
                    .bank-num {
                        display: flex;
                        justify-content: flex-end;
                        font-size: 16px;
                        span {
                            position: relative;
                            top: 4px;
                            margin-right: 20px;
                        }
                        span:last-child {
                            top: 0;
                        }
                    }
                }
            }
            li:last-child {
                margin-bottom: 0;
            }
        }
        .unbind-btn {
            margin-top: 32px;
            box-shadow: none;
            color: #31BC8D;
            border: 1px solid #31BC8D;
        }
        .no-data {
            margin-top: 40px;
            text-align: center;
            color: #969C9E;
        }
    }
</style>